import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  pageDiyForm = "/system-service/diyForm/page",
  getDiyForm = "/system-service/diyForm/get",
  saveDiyForm = "/system-service/diyForm/save",
  updateDiyForm = "/system-service/diyForm/update",
  deleteDiyForm = "/system-service/diyForm/delete",
  batchDeleteDiyForm = "/system-service/diyForm/batchDelete",
  saveGroup = '/system-service/diyForm/saveGroup',
  updateGroup = '/system-service/diyForm/updateGroup',
  batchDeleteGroup = '/system-service/diyForm/batchDeleteGroup',
  deleteGroup = '/system-service/diyForm/deleteGroup',
  importTable = '/system-service/diyForm/importTable',
  batchDeleteField = '/system-service/diyForm/batchDeleteField',
  listField = '/system-service/diyForm/listField',
}

export const listFormField = (params) => defHttp.get({url : Api.listField, params});
export const batchDeleteField = (params) => defHttp.delete({url: `${Api.batchDeleteField}?ids=${params}` });
export const importTable = (params) => defHttp.post({url: Api.importTable, params});
export const getDiyForm = (params) => defHttp.get({url : Api.getDiyForm, params});
export const pageDiyForm = (params) => defHttp.get({url : Api.pageDiyForm, params});

export const saveOrUpdateDiyForm = (params, isUpdate) => {
  let url = isUpdate ? Api.updateDiyForm : Api.saveDiyForm;
  return defHttp.post({url: url, params});
}

export const deleteDiyForm = (params, handleSuccess) => {
  return defHttp.delete({url: Api.deleteDiyForm, data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const batchDeleteDiyForm = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.batchDeleteDiyForm, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}


export const saveOrUpdateGroup = (params, isUpdate) => {
  let url = isUpdate ? Api.updateGroup : Api.saveGroup;
  return defHttp.post({ url: url, params });
}

export const deleteGroup = (params, handleSuccess) => {
  Modal.confirm({
    title: `确认删除${params.name}`,
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteGroup, data: {id: params.id} }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

export const batchDeleteGroup = (params, handleSuccess) => {
  Modal.confirm({
    title: `确认删除`,
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.batchDeleteGroup, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}
